﻿using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace DAL
{
    public class DBSQLServer : DALBase
    {
        /// <summary>
        /// Instancia el objeto con la cadena de conexion y esquema por defecto para el proyecto
        /// </summary>
        public DBSQLServer()
        {
            //this.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["LisBioDB"].ConnectionString;
            Funciones.DataAccessConnection();
            this.ConnectionString = Funciones.connectionString;
            this.Esquema ="";
        }

        public DBSQLServer(string ConnectioString, string Esquema)
        {
            this.ConnectionString = ConnectionString; ;
            this.Esquema = Esquema;
        }
        
        protected override void CambiarEsquema(string Esquema)
        {
            throw new NotImplementedException();
        }

        protected override IDbCommand GetCachedCommand(string CommandText)
        {
            return null;
        }

        protected override void CacheCommand(IDbCommand cmd, object[] Parameters)
        {
            ;
        }

        protected override void ClearCacheCommand()
        {
            throw new NotImplementedException();
        }

        public override IDbCommand NewCommand()
        {
            return new SqlCommand();
        }

        public override IDbConnection NewConnection()
        {
            return new SqlConnection(this.ConnectionString);            
        }

        public override IDbDataParameter NewParameter()
        {
            return new SqlParameter();
        }

        public override void DeriveParameters(IDbCommand cmd)
        {
            SqlCommandBuilder.DeriveParameters((SqlCommand)cmd);
        }

        public override IDataAdapter NewDataAdapter()
        {
            return new SqlDataAdapter();
        }

        public override void DataAdapterFill(IDbCommand cmd, DataTable dt)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                da.SelectCommand = ((SqlCommand)cmd);
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override void DataAdapterFill(IDbCommand cmd, DataSet ds)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                da.SelectCommand = ((SqlCommand)cmd);
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override void DataAdapterFill(IDbCommand cmd, DataSet ds, string SourceTable)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                da.SelectCommand = ((SqlCommand)cmd);
                da.Fill(ds, SourceTable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override void DataAdapterFill(IDbCommand cmd, DataSet ds, int startRecord, int maxRecords, string SourceTable)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                da.SelectCommand = ((SqlCommand)cmd);
                da.Fill(ds, startRecord, maxRecords, SourceTable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
